package com.hnchances.studentscoresystem.service.impl;

import com.hnchances.studentscoresystem.entity.Class;
import com.hnchances.studentscoresystem.mapper.ClassMapper;
import com.hnchances.studentscoresystem.service.ClassService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 班级管理 Service 实现类
 */
@Service
public class ClassServiceImpl extends BaseServiceImpl<Class, Integer, ClassMapper> implements ClassService {

    @Override
    public boolean insert(Class classEntity) {
        // 补全默认值：状态默认为 0（正常）
        if (classEntity.getStatus() == null) {
            classEntity.setStatus(0);
        }
        return mapper.insert(classEntity) > 0;
    }

    @Override
    public Class selectById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Class> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public boolean update(Class classEntity) {
        return mapper.update(classEntity) > 0;
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id) > 0;
    }

    @Override
    public Class selectByClassName(String className) {
        List<Class> classList = mapper.selectByNameLike(className);
        return classList.isEmpty() ? null : classList.get(0);
    }
}